package com.sxf.core;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.Objects;

public class PrimaryKeySerial extends JsonSerializer<Long> {

	@Override
	public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
		String name = gen.getOutputContext().getCurrentName();
		if(StringUtils.isNotBlank(name) && name.startsWith("pk") && !Objects.isNull(value )) {
			gen.writeString(String.valueOf(value));
		}else {
			gen.writeNumber(value);
		}
	}

}
